package com.liu.spring;

import com.liu.spring.domain.User;
import com.liu.spring.mapper.UserMapper;
import com.liu.spring.service.UserService;
import org.mybatis.spring.MapperScan;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.List;


/**
 * @author LIU
 * @version 1.0
 * @date 2024/1/25 10:10
 * @description TODO
 * JDBC工具类实现
 *   ThreadLocal获取连接
 *
 * 手写myBatis源码
 *   mapper代理工厂
 *
 *
 * mybatis底层整和spring
 *     实现@MapperScan功能
 *     FactoryBean生成某一个类型Bean实例,自定义Bean的创建过程
 */
@ComponentScan
@MapperScan("com.liu.spring.mapper")  // 导入扫描类 @Import(LiuMapperScannerRegistrar.class)
public class SpringTest {


    /*

     */
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(SpringTest.class);
        context.refresh();

        System.out.println("========demo=========");
        UserService bean = context.getBean("userService", UserService.class);
        bean.test();

        System.out.println("========mapper=========");
        UserMapper mapper = context.getBean("userMapper", UserMapper.class);
        List<User> result = mapper.getUser("tomcat",10);
        System.out.println(result);
    }
}
